<?php
namespace app\common\event;
use app\common\model\UrmChannelCode as UrmChannelCodeModel;
use think\facade\Log;
use XYCms\WorkWeChat as XYCmsWorkWeChat;

class ChannelCodeTask
{
    public $config_id="";
    public $skip_verify=1;
    public function setData($data=[])
    {
        if(is_numeric($data->skip_verify))
            $this->skip_verify=intval($data->skip_verify);
        if(!empty($data->config_id))
            $this->config_id=$data->config_id;
    }
    public function run()
    {
        $Model= UrmChannelCodeModel::getByConfigId($this->config_id);
        if ($Model){
            $skip_verify=true;
            if ($this->skip_verify != 1){
                $skip_verify=false;
            }
            $da=[
                'config_id'=>$this->config_id,
                'skip_verify'=>$skip_verify
            ];
            $api = new XYCmsWorkWeChat();
            $ret=$api->setContactWay($da);
            Log::error("定时任务执行结果；".json_encode($da,
                    JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES));
            Log::save();
            //TODO　修改失败是否通知指定的成员进行手动修改
            $Model->skip_verify=$this->skip_verify;
            $Model->save();
            return true;
        }
        return false;
    }
}